package com.by.controller;

import cn.hutool.core.bean.BeanUtil;
import com.by.bean.Destination;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.common.group.V;
import com.by.query.DestinationQuery;
import com.by.service.DestinationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "货代报价")
@RequestMapping("/api")
public class DestinationController extends BaseController {
    @Autowired
    DestinationService destinationService;
    @ApiOperation("货代报价保存")
    @PostMapping("/destination")
    public ResultBean save(@Validated @RequestBody Destination destination, BindingResult result){
        V.validate(result);
        int rs=destinationService.save(destination);
        return saveResult(rs);
    }

    @ApiOperation("货代报价列表查询")
    @PostMapping("/destination/list")
    public ResultBean<PageBean> query(@RequestBody DestinationQuery destination){
        PageBean pageBean=destinationService.queryByMap(BeanUtil.beanToMap(destination));
        return success("货代报价列表",pageBean);
    }

    @ApiOperation("货代报价修改")
    @PutMapping("/destination/update")
    public ResultBean update(@RequestBody Destination destination){
        int rs=destinationService.update(destination);
        return updateResult(rs);
    }

    @ApiOperation("货代报价查询")
    @GetMapping("/destination/select")
    public ResultBean get(@RequestParam("destination_coding") String destination_coding){
        Destination destination=destinationService.get(destination_coding);
        return success("货代报价信息",destination);
    }
}
